/*************************************************************************
	> File Name: Sem.hpp
	> Author: H.M. Lau
	> Mail: hm.lau@outlook.com
	> Created Time: 2023/09/28 17:10
 ************************************************************************/

#pragma once

#include "comm.hpp"

class Sem
{
public:
    Sem (int value)
    {
        sem_init(&_sem, 0, value);
    }

    void p()
    {
        sem_wait(&_sem);
    }

    void v()
    {
        sem_post(&_sem);
    }

    virtual ~Sem ()
    {
        sem_destroy(&_sem);
    }

private:
    sem_t _sem;
};
